<template>
  <div>
    <el-dialog title="订单信息" :visible.sync="show" width="70%" append-to-body>
      <div>
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="订单编号" prop="sn">
            <el-input
              v-model="queryParams.sn"
              placeholder="请输入订单编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="用户昵称" prop="memberName">
            <el-input
              v-model="queryParams.memberName"
              placeholder="请输入用户昵称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >
              搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
        </el-row>
        <el-table v-loading="loading" :data="dataList" border stripe>
          <el-table-column label="#" fixed="left" type="index" width="80" align="center">
            <template slot-scope="scope">
              <span>{{
                (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="订单编号"
            align="center"
            prop="sn"
            fixed="left"
            width="260"
          />
          <el-table-column
            label="用户昵称"
            align="center"
            prop="memberName"
            min-width="120"
          />
          <el-table-column label="商品类型" align="center" width="120">
            <template slot-scope="scope">
              {{ goodsType(scope.row.goodsType) }}
            </template>
          </el-table-column>
          <el-table-column
            label="商品价格(元)"
            align="center"
            prop="goodsPrice"
            width="120"
          />
          <el-table-column label="订单类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.memberType == 2 ? 'warning' : 'success'"
                effect="plain"
              >
                {{ scope.row.memberType == 2 ? "临时订单" : "会员订单" }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="订单状态" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.orderStatus == 'PAID'
                    ? 'success'
                    : scope.row.orderStatus == 'UNPAID'
                    ? 'warning'
                    : 'danger'
                "
                effect="plain"
              >
                {{
                  scope.row.orderStatus == "PAID"
                    ? "已支付"
                    : scope.row.orderStatus == "UNPAID"
                    ? "未支付"
                    : "已取消"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="订单取消原因"
            align="center"
            prop="cancelReason"
            min-width="120"
          />
          <el-table-column label="停车点位" align="center" prop="areaName" width="180" />
          <el-table-column label="创建类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.payType == 1 ? 'success' : 'warning'"
                effect="plain"
              >
                {{ scope.row.payType == 1 ? "用户创建" : "后台创建" }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="完成时间"
            align="center"
            prop="completeTime"
            width="180"
          />
          <el-table-column
            label="支付时间"
            align="center"
            prop="paymentTime"
            width="180"
          />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder } from "@/api/weiriya/order";
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    // 停车点位ID
    id: {
      type: String,
      default: "",
    },
  },
  computed: {
    show: {
      get() {
        return this.value;
      },
      set() {
        this.$emit("input", false);
      },
    },
  },
  watch: {
    value(val) {
      if (val) {
        this.queryParams.areaId = this.id;
        this.getList();
      }
    },
  },
  data() {
    return {
      loading: false, // 加载状态
      showSearch: true, // 显示搜索条件
      total: 0, // 总条数
      dataList: [], // 数据列表
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaId: null,
        sn: null,
        memberName: null,
      },
    };
  },
  methods: {
    // 查询支付订单列表
    getList() {
      this.loading = true;
      listOrder(this.queryParams)
        .then((res) => {
          this.dataList = res.rows;
          this.total = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 获取商品类型名称
    goodsType(val) {
      let list = [
        { label: "充电月卡", value: "MONTH_CHARGE" },
        { label: "充电季卡", value: "QUARTER_CHARGE" },
        { label: "充电年卡", value: "YEAR_CHARGE" },
        { label: "停车月卡", value: "MONTH_DEPOSIT" },
        { label: "停车季卡", value: "QUARTER_DEPOSIT" },
        { label: "停车年卡", value: "YEAR_DEPOSIT" },
        { label: "余额充值", value: "WALLET_RECHARGE" },
      ];
      let item = list.find((i) => i.value == val);
      return item ? item.label : val;
    },
    // 关闭弹窗
    handleCancel() {
      this.show = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
